<?php
/**
 * XmuSlh, web platform of Student Association Federation of Xiamen University
 * 
 * Rewritting.
 * 
 * Author：Flymorn 
 * Source：飘易博客
 * Categories：PHP编程 
 * PostTime：2008-4-28 11:38:37
 */

/**
 * 由于生成验证码图片的脚本.
 * 
 * @author		ytukie <ytukie@gmail.com>
 * @version		0.1
 */

// XmuSlh only.
// if ( !defined('XMUSLH')) { exit(1); }

session_start();

//生成验证码图片
Header("Content-type: image/gif");

$im = imagecreate(52, 16);
$back = imagecolorallocate($im, 255, 255, 255);

imagefill($im, 0, 0, $back); //背景
srand((double)microtime()*1000000);

$vcodes = '';
//生成4位数字
for ($i = 0;$i < 4; ++$i){
	$color = imagecolorallocate($im, rand(0, 100),rand(0, 100),rand(0, 100));
	$authnum = rand(1, 9);
	$vcodes .= $authnum;
	imagestring($im, 5, 2+$i*12, 3, $authnum, $color);
}

for ($i = 0;$i < 100; ++$i) //加入干扰象素
{
	$randcolor = imagecolorallocate($im, rand(0,255), rand(0,255), rand(0,255));
	imagesetpixel($im, rand()%70 , rand()%30 , $randcolor);
}

imagegif($im);
imagedestroy($im);

// 使用$_SESSION['authcode']验证
$_SESSION['authcode'] = $vcodes;
?>